package com.example.e_comm.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.e_comm.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Set;

@Mapper
public interface UserMapper extends BaseMapper<User> {

    /**
     * 根据角色ID获取用户列表
     * @param roleId 角色ID
     * @return 用户列表
     */
    @Select("SELECT u.* FROM users u " +
            "INNER JOIN user_role ur ON u.id = ur.user_id " +
            "WHERE u.deleted = 0 AND ur.role_id = #{roleId} AND ur.deleted = 0")
    List<User> getUsersByRoleId(@Param("roleId") Long roleId);

    /**
     * 根据用户名查询用户
     * @param username 用户名
     * @return 用户对象
     */
    @Select("SELECT * FROM users WHERE username = #{username} AND deleted = 0")
    User selectByUsername(@Param("username") String username);
    /**
     * 根据用户ID获取用户列表
     * @param userId 用户ID
     * @return 用户列表
     */
    @Select("SELECT * FROM users WHERE id = #{userId} AND deleted = 0")
    List<User> getUsersById(@Param("userId") Long userId);
    /**
     * 根据用户ID获取用户列表
     * @param userIdSet 用户ID集合
     * @return 用户列表
     */
    @Select("SELECT * FROM users WHERE id IN (#{userIdSet}) AND deleted = 0")
    List<User> getUsersByIdSet(@Param("userIdSet") Set<Long> userIdSet);
}
